home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blitzblank / sources / screenreq < prev    next >
Text File  |  1993-09-17  |  8KB  |  335 lines

  1. CloseEd
  2.  
  3. ;Screenmoderequester by Thomas Boerkel
  4. ;
  5. ;This routine displays a screenmoderequester and can be used in your own
  6. ;programs, if you give credit.
  7. ;The routine uses 4 global vars for the modeid, width, height and depth.
  8. ;You can provide these vars with values and the routine will try to mark
  9. ;that screenmode in it`s list.
  10. ;If you want to open a screen with the given modeid, you have to open
  11. ;it with OpenScreenTagList_() at this time. You then can use that screen with
  12. ;Blitz2-commands with FindScreen 0 or FindScreen 0,"Name"
  13.  
  14. DEFTYPE.l
  15.  
  16. Statement screenreq{}
  17. SHARED modeid.l,width.l,height.l,depth.l
  18.  
  19. XINCLUDE gadtools.bb2
  20.  
  21. NEWTYPE.scrtags
  22. a.l
  23. b
  24. c
  25. d
  26. e
  27. f
  28. g
  29. h
  30. i
  31. j
  32. k
  33. l
  34. m
  35. n
  36. o
  37. p
  38. q
  39. r
  40. s
  41. End NEWTYPE
  42.  
  43. DEFTYPE.List *scrlist
  44. DEFTYPE.Node *scrnode,*tempnode
  45. DEFTYPE.Screen *wbscreen
  46. DEFTYPE.NewWindow newwindow
  47. DEFTYPE.Window *mywindow
  48. DEFTYPE.NewGadget ng
  49. DEFTYPE.Gadget *gad
  50. DEFTYPE.NameInfo screenname
  51. DEFTYPE.DimensionInfo screendim
  52. DEFTYPE.DisplayInfo screendisp
  53. DEFTYPE.MonitorInfo moninfo
  54. DEFTYPE.scrtags tags
  55. DEFTYPE.IntuiMessage *imsg
  56. DEFTYPE.TextAttr      topaz80
  57. DEFTYPE.l mi,a,i,avail,prop,s,*vi,*glist,result,class,code,d,m
  58.  
  59. ;Special trick: Assembler subroutine which is called by GadTools to
  60. ;calculate the colors from the depth. The colors are then displayed
  61. ;beside the depth-slider
  62. If 0
  63.   lab:
  64.   MOVE.l d1,-(a7)
  65.   MOVE.l d0,d1
  66.   MOVE.l #1,d0
  67.   LSL.l d1,d0
  68.   MOVE.l (a7)+,d1
  69.   RTS
  70. EndIf
  71.  
  72. #GAD_OK=0
  73. #GAD_CANCEL=1
  74. #GAD_LIST=2
  75. #GAD_SLIDER=3
  76. #GAD_RESOLUTION=4
  77.  
  78. #US=95
  79.  
  80. gtext0$="_OK"+Chr$(0)
  81. gtext1$="C_ancel"+Chr$(0)
  82. gtext2$="Available _Screenmodes"+Chr$(0)
  83. gtext3$="_Colors:    "+Chr$(0)
  84. fname$="topaz.font"+Chr$(0)
  85. topaz80\ta_Name=&fname$,8,0,0
  86.  
  87.  
  88. m=modeid
  89. d=depth
  90. s=-1
  91. *wbscreen=LockPubScreen_(0)
  92.  
  93. ;Is the given mode available? If not: Use WB`s modeid
  94. If (m=0 AND d=0) OR ModeNotAvailable_ (m)
  95.   m=GetVPModeID_(*wbscreen\ViewPort)
  96.   d=*wbscreen\BitMap\Depth
  97. EndIf
  98.  
  99. ;If it is the default-monitor then get the right monitor-ID
  100. If (m AND #MONITOR_ID_MASK)=0
  101.   GetDisplayInfoData_ 0,moninfo,SizeOf.MonitorInfo,#DTAG_MNTR,m
  102.   m OR moninfo\Header\DisplayID
  103. EndIf
  104.  
  105. a=0
  106. mi=NextDisplayInfo_(-1)
  107. Repeat
  108.   a+1
  109.   mi=NextDisplayInfo_(mi)
  110. Until mi=-1
  111.  
  112. s=-1
  113.  
  114. Dim scrn$(a)
  115. Dim scrm.l(a)
  116. Dim scrx.l(a)
  117. Dim scry.l(a)
  118. Dim scrd.l(a)
  119. *scrlist=AllocMem_(SizeOf.List,#MEMF_CLEAR)
  120. *scrlist\lh_Head=&*scrlist\lh_Tail
  121. *scrlist\lh_Tail=0
  122. *scrlist\lh_TailPred=&*scrlist\lh_Head
  123. mi=NextDisplayInfo_(-1)
  124. i=-1
  125. Repeat
  126.   GetDisplayInfoData_ 0,screendisp,SizeOf.DisplayInfo,#DTAG_DISP,mi
  127.   avail=screendisp\NotAvailable
  128.   prop=screendisp\PropertyFlags
  129.   If (prop AND #DIPF_IS_HAM)=0 AND (prop AND #DIPF_IS_DUALPF)=0 AND (prop AND #DIPF_IS_EXTRAHALFBRITE)=0 AND avail=0
  130.     If mi AND #MONITOR_ID_MASK
  131.  
  132.       If GetDisplayInfoData_(0,screenname,SizeOf.NameInfo,#DTAG_NAME,mi)
  133.         i+1
  134.         GetDisplayInfoData_ 0,screendim,SizeOf.DimensionInfo,#DTAG_DIMS,mi
  135.         scrd(i)=screendim\MaxDepth
  136.         scrx(i)=screendim\TxtOScan\MaxX+1
  137.         scry(i)=screendim\TxtOScan\MaxY+1
  138.         scrm(i)=mi
  139.         scrn$(i)=Peek$(&screenname\Name)
  140.         resolution$=Str$(scrx(i))+" x "+Str$(scry(i))
  141.         scrn$(i)+String$(" ",44-Len(resolution$)-Len(scrn$(i)))+resolution$+Chr$(0)
  142.         If mi=m
  143.           s=i
  144.         EndIf
  145.         *scrnode=AllocMem_(SizeOf.Node,#MEMF_CLEAR)
  146.         *scrnode\ln_Name=&scrn$(i)
  147.         AddTail_ *scrlist,*scrnode
  148.       EndIf
  149.     EndIf
  150.   EndIf
  151.   mi=NextDisplayInfo_(mi)
  152. Until mi=-1
  153. a=i
  154.  
  155. *glist=0
  156. *vi=GetVisualInfoA_(*wbscreen,0)
  157. *gad=CreateContext_(&*glist)
  158.  
  159. tags\a=#GT_Underscore
  160. tags\b=#US
  161. tags\c=0
  162.  
  163. ng\ng_LeftEdge=30,160,60,12,>ext0$,topaz80,#GAD_OK,0,*vi,0
  164. *gad=CreateGadgetA_(#BUTTON_KIND,*gad,ng,tags)
  165.  
  166. ng\ng_LeftEdge=330,160,60,12,>ext1$,topaz80,#GAD_CANCEL
  167. *gad=CreateGadgetA_(#BUTTON_KIND,*gad,ng,tags)
  168.  
  169. tags\c=#GTLV_Labels
  170. tags\d=*scrlist
  171. tags\e=#GTLV_Top
  172. tags\f=s
  173. tags\g=#GTLV_ShowSelected
  174. tags\h=0
  175. tags\i=#GTLV_Selected
  176. tags\j=s
  177. tags\k=0
  178. ng\ng_LeftEdge=20,30,380,100,>ext2$,topaz80,#GAD_LIST
  179. *gad1=CreateGadgetA_(#LISTVIEW_KIND,*gad,ng,tags)
  180.  
  181. f$="%3ld"+Chr$(0)
  182. tags\c=#GTSL_Min
  183. tags\d=1
  184. tags\e=#GTSL_Max
  185. tags\f=scrd(s)
  186. tags\g=#GTSL_Level
  187. tags\h=d
  188. tags\i=#GTSL_LevelFormat
  189. tags\j=&f$
  190. tags\k=#GTSL_MaxLevelLen
  191. tags\l=3
  192. tags\m=#GTSL_DispFunc
  193. tags\n=?lab
  194. tags\o=#GA_RelVerify
  195. tags\p=True
  196. tags\q=0
  197. ng\ng_LeftEdge=190,140,130,11,>ext3$,topaz80,#GAD_SLIDER
  198. *gad2=CreateGadgetA_(#SLIDER_KIND,*gad1,ng,tags)
  199.  
  200. title$="Please choose screenmode..."+Chr$(0)
  201. newwindow\LeftEdge=*wbscreen\Width/2-210,*wbscreen\Height/2-90,420,180,0,1,#IDCMP_CLOSEWINDOW|#LISTVIEWIDCMP|#IDCMP_VANILLAKEY
  202. newwindow\Flags=#WFLG_CLOSEGADGET|#WFLG_DRAGBAR|#WFLG_DEPTHGADGET|#WFLG_ACTIVATE|#RMBTRAP
  203. newwindow\FirstGadget=*glist,0,&title$,0,0,-1,-1,-1,-1,#WBENCHSCREEN
  204. *mywindow=OpenWindow_(newwindow)
  205. If *mywindow
  206.   GT_RefreshWindow_ *mywindow,0
  207.   result=1
  208.   Repeat
  209.     WaitPort_ *mywindow\UserPort
  210.     *imsg=GT_GetIMsg_(*mywindow\UserPort)
  211.     If *imsg
  212.       class=*imsg\Class
  213.       *gad=*imsg\IAddress
  214.       code=*imsg\Code
  215.       GT_ReplyIMsg_(*imsg)
  216.       Select class
  217.         Case #IDCMP_CLOSEWINDOW
  218.           result=0
  219.         Case #IDCMP_VANILLAKEY
  220.           Select code
  221.             Case 111 ;o
  222.               modeid=scrm(s)
  223.               width=scrx(s)
  224.               height=scry(s)
  225.               depth=d
  226.               result=0
  227.             Case 79 ;O
  228.               modeid=scrm(s)
  229.               width=scrx(s)
  230.               height=scry(s)
  231.               depth=d
  232.               result=0
  233.             Case 97 ;a
  234.               result=0
  235.             Case 65 ;A
  236.               result=0
  237.             Case 27 ;ESC
  238.               result=0
  239.             Case 99 ;c
  240.               If d<scrd(s)
  241.                 d+1
  242.                 tags\a=#GTSL_Level
  243.                 tags\b=d
  244.                 tags\c=0
  245.                 GT_SetGadgetAttrsA_ *gad2,*mywindow,0,tags
  246.               EndIf
  247.             Case 67 ;C
  248.               If d>1
  249.                 d-1
  250.                 tags\a=#GTSL_Level
  251.                 tags\b=d
  252.                 tags\c=0
  253.                 GT_SetGadgetAttrsA_ *gad2,*mywindow,0,tags
  254.               EndIf
  255.             Case 115 ;s
  256.               If s<a
  257.                 s+1
  258.                 tags\a=#GTLV_Top
  259.                 tags\b=s
  260.                 tags\c=#GTLV_Selected
  261.                 tags\d=s
  262.                 tags\e=0
  263.                 GT_SetGadgetAttrsA_ *gad1,*mywindow,0,tags
  264.                 modslide=1
  265.               EndIf
  266.             Case 83 ;S
  267.               If s>0
  268.                 s-1
  269.                 tags\a=#GTLV_Top
  270.                 tags\b=s
  271.                 tags\c=#GTLV_Selected
  272.                 tags\d=s
  273.                 tags\e=0
  274.                 GT_SetGadgetAttrsA_ *gad1,*mywindow,0,tags
  275.                 modslide=1
  276.               EndIf
  277.           End Select
  278.         Case #IDCMP_GADGETUP
  279.           Select *gad\GadgetID
  280.             Case #GAD_OK
  281.               modeid=scrm(s)
  282.               width=scrx(s)
  283.               height=scry(s)
  284.               depth=d
  285.               result=0
  286.             Case #GAD_CANCEL
  287.               result=0
  288.             Case #GAD_LIST
  289.               s=code
  290.               modslide=1
  291.             Case #GAD_SLIDER
  292.               d=code
  293.           End Select
  294.       End Select
  295.       If modslide=1
  296.         modslide=0
  297.         If scrd(s)<d
  298.           d=scrd(s)
  299.         EndIf
  300.         tags\a=#GTSL_Max
  301.         tags\b=scrd(s)
  302.         tags\c=#GTSL_Level
  303.         tags\d=d
  304.         tags\e=0
  305.         GT_SetGadgetAttrsA_ *gad2,*mywindow,0,tags
  306.       EndIf
  307.     EndIf
  308.   Until result=0
  309.   CloseWindow_ *mywindow
  310.   FreeGadgets_ *glist
  311.   FreeVisualInfo_ *vi
  312.  
  313. EndIf
  314. *tempnode=*scrlist\lh_TailPred
  315. While *tempnode\ln_Pred
  316.   *scrnode=*tempnode\ln_Pred
  317.   FreeMem_ *tempnode,SizeOf.Node
  318.   *tempnode=*scrnode
  319. Wend
  320. FreeMem_ *scrlist,SizeOf.List
  321. UnlockPubScreen_ 0,*myscreen
  322. End Statement
  323.  
  324. ;This is to test the requester:
  325.  
  326. ;screenreq{}
  327. ;NPrint Hex$(modeid)
  328. ;NPrint width
  329. ;NPrint height
  330. ;NPrint depth
  331. ;End
  332.  
  333.  
  334.  
  335.